package days45.title206;

import org.w3c.dom.Node;

class Solution {
    public ListNode reverseList(ListNode head) {
        if (head ==null)
            return null;
        if (head.next==null)
            return head;
        ListNode tmpNode = new ListNode();
        tmpNode.next = head;
        head = head.next;
        tmpNode.next.next=null;
        while (head!=null){
            ListNode node = head;
            head = head.next;
            node.next = tmpNode.next;
            tmpNode.next = node;
        }
        return tmpNode.next;
    
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}